Skip to content

Update pending in-person profile queries to consider enrollment expiration#11129

Closed
aduth wants to merge 11 commits intomainfrom
aduth-profile-expired-enrollment-ipp-pending
Closed

Update pending in-person profile queries to consider enrollment expiration#11129
aduth wants to merge 11 commits intomainfrom
aduth-profile-expired-enrollment-ipp-pending

Conversation

@aduth
Copy link
Copy Markdown
Contributor

@aduth aduth commented Aug 22, 2024

🛠 Summary of changes

Updates queries for pending in-person profiles profiles to consider whether the associated enrollment is expired.

This follows #11105 (LG-14231), which updated the proofing results job to reset the profile pending timestamp for an expired enrollment. The intent with these changes is to accommodate both new and old profiles which may or may not have this value reset.

This is a (temporary?) alternative to a solution which would involve updating database records to reset the timestamp for profiles associated with expired enrollments: #11130

📜 Testing Plan

Override config/application.yml to prevent results job from automatically marking pending profiles as successful in local development:

in_person_enrollments_ready_job_cron: 0 0 29 2 1
  1. Have both the IdP and sample application running simultaneously
  2. In a private browsing window, go to http://localhost:9292
  3. Change "Level of Service" to "Identity-verified"
  4. Click "Sign in"
  5. Create a new account
  6. Complete identity verification using in-person proofing
  7. Once you reach the barcode step, close your browser
  8. Open a rails console: rails console
  9. Manually mark the enrollment as expired, without updating associated profile (simulate behavior prior to LG-14231: Users can't access accounts after enrollment expires #11105): InPersonEnrollment.last.update(status: :expired)
  10. Repeat Steps 2-4
  11. Sign in with the account you created previously

Before: You'd be redirected to the account page (wrong), and the account page would raise an exception when trying to access due_date property on the pending enrollment
After: You're redirected into the identity verification flow

create(:in_person_enrollment, :pending, user: user, profile: profile)
fully_registered
profiles do
[association(:profile, :with_pii, :in_person_verification_pending, user: instance)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooo love this cleanup to use the factory associations better

Copy link
Copy Markdown
Contributor Author

@aduth aduth Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, to be honest it was a bit of a nightmare to figure out how to implement this correctly, but it does feel a lot more reliable / portable, and supports overriding trait attributes in a way that's not possible with the lifecycle hooks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same! Big fan. 🤩

Comment on lines +71 to +73
# See: Idv::Session#create_profile_from_applicant_with_password

before do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style, I'd remove the space between?

Suggested change
# See: Idv::Session#create_profile_from_applicant_with_password
before do
# See: Idv::Session#create_profile_from_applicant_with_password
before do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yeah. The padding line was intentional to try to "link" it more with the context block than the before block. But maybe in that case the comment should live above the context line? Not sure how I feel about this.

Copy link
Copy Markdown
Contributor

@zachmargolis zachmargolis Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my thinking is the context description is what we want to happen, the before block (or sometimes a let) is how we want that to happen, and in this case, the comment clarifies the how

# See: Idv::Session#create_profile_from_applicant_with_password

before do
profile.in_person_enrollment.update(status: :establishing, profile: nil)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would a Profile be associated with an InPersonEnrollment and the InPersonEnrollment have profile set to nil?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the comment above help clarify?

# When marking profile as pending in-person proofing, the enrollment hasn't yet been linked to
# the profile.
#
# See: Idv::Session#create_profile_from_applicant_with_password

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe clarify that it's still linked to the user via the in_person_enrollment.user_id?


def in_person_verification_pending?
in_person_verification_pending_at.present?
in_person_verification_pending_at.present? && !in_person_enrollment&.expired?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is InPersonEnrollment not Expired checked rather than InPersonEnrollment is pending?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good call, I'll update to have them in sync.

def self.in_person_verification_pending
where.not(in_person_verification_pending_at: nil)
where.not(in_person_verification_pending_at: nil).
left_outer_joins(:in_person_enrollment).where.not(in_person_enrollment: { status: :expired })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question for this change.

@gina-yamada
Copy link
Copy Markdown
Contributor

@aduth Thanks for digging into this. After further investigation, Team Joy is going to move forward with updating the data (setting profile.in_person_verification_pending_at to nil in the USPS job) with the PR and then backfilling the data like what you are doing in PR, with some updates.

I think we can close this pull request now.

@aduth
Copy link
Copy Markdown
Contributor Author

aduth commented Aug 28, 2024

@aduth Thanks for digging into this. After further investigation, Team Joy is going to move forward with updating the data (setting profile.in_person_verification_pending_at to nil in the USPS job) with the PR and then backfilling the data like what you are doing in PR, with some updates.

I think we can close this pull request now.

Makes sense to me 👍

@aduth aduth closed this Aug 28, 2024
@aduth aduth deleted the aduth-profile-expired-enrollment-ipp-pending branch August 28, 2024 16:23
@aduth
Copy link
Copy Markdown
Contributor Author

aduth commented Aug 29, 2024

Though I'd like to salvage some of the spec factory improvements here, I'll put together a pull request for just those changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants